package com.wangs.case03_16110100624;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class WelcomeActivity extends AppCompatActivity {
    private Button btn_setting;
    private TextView tv_username,tv_password;
    //简单存储-存借助editor--commit
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;
    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        tv_username = findViewById(R.id.tv_username);
        tv_password = findViewById(R.id.tv_password);
        btn_setting = findViewById(R.id.btn_setting);

        tv_username.setText(getIntent().getStringExtra("username"));
        tv_password.setText(getIntent().getStringExtra("password"));

        //初始化(起名字，权限)
        sp = getSharedPreferences("case03_sp",MODE_PRIVATE);
        //打开文件
        editor = sp.edit();
        //        向文件发送数据
        editor.putString("username",getIntent().getStringExtra("username"));
        //
        editor.commit();
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(WelcomeActivity.this,SettingActivity.class);
                startActivity(intent);
            }
        };
//        listener对象建立，什么时候用什么时候设置，可以加很多响应，switch
        btn_setting.setOnClickListener(listener);

    }
}
